package com.hsteach.web.controller.patrol;

import com.github.pagehelper.PageHelper;
import com.hsteach.common.core.controller.BaseController;
import com.hsteach.common.core.domain.AjaxResult;
import com.hsteach.common.core.page.TableDataInfo;
import com.hsteach.dao.domain.patrol.Behavior;
import com.hsteach.dao.domain.patrol.BehaviorCategory;
import com.hsteach.service.patrol.BehaviorCategoryService;
import com.hsteach.service.patrol.BehaviorDetail;
import com.hsteach.web.controller.patrol.dto.BehaviorCategoryDTO;
import com.hsteach.web.controller.patrol.dto.BehaviorDetailDTO;
import com.hsteach.web.controller.patrol.dto.QueryBehaviorDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author mgb
 * @version PatrolController, java v1.0 2023-11-08 22:19 EXP $
 */
@Api(value = "行为条例", tags = "行为条例")
@RestController
@RequestMapping("/patrol/behavior")
public class PatrolOrdinanceController  extends BaseController {


    @Autowired
    public BehaviorCategoryService behaviorCategoryService;

    @ApiOperation("增加分类")
    @PostMapping("/addCategory")
    public TableDataInfo addCategory(@RequestBody BehaviorCategoryDTO behaviorCategoryDTO){
        BehaviorCategory behaviorCategory = new BehaviorCategory();
        BeanUtils.copyProperties(behaviorCategoryDTO,behaviorCategory);
        return  behaviorCategoryService.addCategory(behaviorCategory);
    }

    @ApiOperation("修改分类名称")
    @PostMapping("/updateCategory")
    public AjaxResult updateCategory(@RequestBody BehaviorCategoryDTO behaviorCategoryDTO){
        BehaviorCategory behaviorCategory = new BehaviorCategory();
        BeanUtils.copyProperties(behaviorCategoryDTO,behaviorCategory);
        return  behaviorCategoryService.updateCategory(behaviorCategory);
    }


    @ApiOperation("修改分类顺序")
    @PostMapping("/updateCategorySort")
    public AjaxResult updateCategorySort(@RequestBody List<BehaviorCategoryDTO> behaviorCategoryDTOS){
        return  behaviorCategoryService.updateCategorySort(behaviorCategoryDTOS);
    }
    @ApiOperation("查询分类")
    @PostMapping("/queryCategory")
    public AjaxResult queryCategory(@RequestParam(required = false) String firstCategory,@RequestParam String orgCode){
        return  AjaxResult.success("查询成功",behaviorCategoryService.queryCategory(firstCategory,orgCode));
    }


    @ApiOperation("查询行为信息")
    @PostMapping("/queryBehavior")
    public TableDataInfo queryBehavior(QueryBehaviorDTO queryBehaviorDTO){

        return behaviorCategoryService.queryBehavior(queryBehaviorDTO);
    }


    @ApiOperation("添加细则")
    @PostMapping("/addBehavior")
    public AjaxResult addBehavior(@RequestBody BehaviorDetailDTO behaviorDetailDTO){
        BehaviorDetail behaviorDetail = new BehaviorDetail();
        BeanUtils.copyProperties(behaviorDetailDTO,behaviorDetail);
        return  success("添加成功",behaviorCategoryService.addBehavior(behaviorDetail));
    }

    @ApiOperation("编辑细则")
    @PostMapping("/updateBehavior")
    public AjaxResult updateBehavior(@RequestBody BehaviorDetailDTO behaviorDetailDTO){
        BehaviorDetail behaviorDetail = new BehaviorDetail();
        BeanUtils.copyProperties(behaviorDetailDTO,behaviorDetail);
        return  success(behaviorCategoryService.updateBehavior(behaviorDetail));
    }

    @ApiOperation("删除细则")
    @PostMapping("/deleteBehavior")
    public AjaxResult deleteBehavior(int id){
      return behaviorCategoryService.deleteBehavior(id);
    }

    @ApiOperation("删除分类")
    @PostMapping("/deleteCategory")
    public AjaxResult deleteCategory(@RequestParam int id) {
        return success(behaviorCategoryService.deleteCategory(id));
    }


}
